﻿<link href="~/lib/ztree/ztree.css" rel="stylesheet" asp-append-version="true" />
<script src="~/lib/ztree/ztree.core-3.5.37.min.js" asp-append-version="true"></script>
@*<script src="~/lib/ztree/ztree.exedit-3.5.37.js" asp-append-version="true"></script>*@
<script src="~/lib/ztree/ztree.excheck-3.5.37.min.js" asp-append-version="true"></script>
<script type="text/javascript">
	$(document).ready(function () {
		var treeSetting = {
			check: {
				enable: true
			},
			view: {
				selectedMulti: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onCheck: function (event, treeId, treeNode) {
					var nodesChecked = $.fn.zTree.getZTreeObj(treeId).getCheckedNodes();
					var selected = [];
					for (i = 0; i < nodesChecked.length; i++) {
						if (!nodesChecked[i].isParent) {
							selected.push(nodesChecked[i]);
						}
					}
					var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
					if (parent.@(ViewData["callback"])) {
						parent.@(ViewData["callback"])(index, selected);
					} else {
						parent.layer.close(index);
					}
				},
				onClick: function (event, treeId, treeNode, clickFlag) {
				},
			}
		};
		utils.ajaxPost('@(Url.Action("GetTreeData", "IMS_ProdCat"))', { catid: "@(ViewData["catid"])",orgid:"@(ViewData["orgid"])" }, function (resp) {
			var data = resp.data || [];
			var treeData = [];
			treeData.push({
				id: '0',
				pId: "-1",
				name: "全部",
				code: "",
				isParent: true,
				open: true
			});
			$.each(data, function (idx,item) {
				treeData.push(Object.assign({}, item, {
					id: item.ID.toString(),
					pId: item.PID.toString(),
					name: item.Name,
					code: item.Code,
					open: true,
					checked:false//
				}));
			});
			$.fn.zTree.init($("#@(ViewData["id"])"), treeSetting, treeData);
		});
	});
</script>